{include file="public/toper" /}
<style>
    .demo_class {width: 300px !important;}
    .demo_class .layui-layer-content {padding: 0 0 0 15px !important;}
    .laytable-cell-1-2 img {width: 50px !important;}
    .thumb-show{width: 100%;height: 100%;}
</style>
<script type="text/javascript" src="/static/js/myajax.js"></script>
<div class="x-nav">
    <span class="layui-breadcrumb">
        <a href="">门店管理</a>
        <a href="">门店列表</a>
    </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">&#xe666;</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <div class="layui-col-md12 x-so">
            <input type="text" name="sreach" value=""  style="width:250px;" id="key"   placeholder="请输入店名、地址、电话、" autocomplete="off" class="layui-input">
            <button class="layui-btn" id="search"><i class="layui-icon">&#xe615;</i></button>
        </div>
    </div>
        <button class="layui-btn" onclick="x_admin_show('添加门店','{:url(\'Store/add\')}')"><i class="layui-icon"></i>添加</button>
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>
<script type="text/html" id="img">
    <img src="{{d.img}}" class="thumb" thumb="{{ d.img }}"/>
    <div class="layui-table-cell laytable-cell-1-phone"></div>
</script>
<script type="text/html" id="statusTpl">
    <input type="checkbox" name="state" value="{{ d.state }}" lay-skin="switch" lay-filter="switchStatus" lay-text="正常|关闭" {{ d.state == 1 ? 'checked' : '' }} data-href="{:url('state')}?table=store&id={{ d.store_id }}">
</script>
<script type="text/html" id="action">
    <button class="layui-btn layui-btn layui-btn-xs"  onclick="x_admin_show('编辑门店','{:url(\'Store/edit\')}?id={{d.store_id}}')"><i class="layui-icon">&#xe642;</i>编辑</button>
    <button class="layui-btn-danger layui-btn layui-btn-xs del_btn" id="{{d.store_id}}" lay-event="del"><i class="layui-icon">&#xe640;</i>删除</button>
</script>
<script>
    layui.use('table', function(){
        var table = layui.table, $ = layui.jquery;
        var layer = layui.layer;
        var loading = layer.load(1, {shade: [0.1,'#fff'] });
        var tableIn = table.render({
            method: 'post',
            elem: '#test'
            ,url: "{:url('Store/index')}"
            ,id:'test'
            ,cols: [[
                {field:'store_id', width:80, title: '序号',align: 'center',type:'numbers'}
                ,{field:'store_id', width:150, title: '门店id',align: 'center'}
                ,{field:'name', width:200, title: '门店名称',align: 'center'}
                ,{width:150,title: '门店图片',align: 'center',toolbar: '#img'}
                ,{field:'phone', width:150,title: '门店电话',align: 'center'}
                ,{field:'address', width:250,title: '门店地址',align: 'center'}
                ,{field: 'state', width: 140,title: '状态', templet: '#statusTpl'}
                ,{width: 190,title: '操作', align: 'center', toolbar: '#action'}
            ]]
            ,page: true
            ,limit: 30
            ,limits:[30,60,90,120,150,180,210,240,270,300]
        });
        layer.close(loading);
        //搜索
        $('#search').on('click', function () {
            var loading = layer.load(1, {shade: [0.1,'#fff'] });
            var key = $('#key').val();
            tableIn.reload({
                where: {key: key}
            });
            layer.close(loading);
        });



        //删除
        table.on('tool(test)', function(obj) {
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('您确定要删除【'+data.name+'】吗？',{btnAlign: 'c'}, function(index){
                    var loading = layer.load(1, {shade: [0.1,'#fff'] });
                    $.get("{:url('Store/del')}",{store_id:data.store_id},function(res){
                        layer.close(loading);
                        if(res.code==200){
                            layer.msg(res.msg,{time:1000,icon:1});
                            tableIn.reload();
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
        });



        var layertip = null;
        $(document).on('mouseenter','.thumb',function(){
            //console.log(event);
            var im = ('<img class="thumb-show" src="'+$(this).attr('thumb')+'" >');
            var link = $(this).attr('href');
            //layertip=layer.tips('<img style="" src='"/ >', this, { tips:[2,'#009688'] ,area: ['宽度', '高度'],time:false});
            layertip = layer.tips( im, this, {
                tips: [2,'#009688'],
                skin: 'demo_class',
                time: false,
            });
        });

        //隐藏缩略图
        $(document).on('mouseleave','.thumb', function() {
            layer.close(layertip);
        });

    });
</script>
{include file="public/footer"/}